home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1320
/
1320.xpi
/
chrome
/
gmanager.jar
/
content
/
alert
/
alert.js
< prev
next >
Wrap
Text File
|
2010-01-22
|
6KB
|
203 lines
// Gmail Manager
// By Todd Long <longfocus@gmail.com>
// http://www.longfocus.com/firefox/gmanager/
var gmanager_Alert = new function()
{
this.__proto__ = new gmanager_BundlePrefix("gmanager-alert-");
this.NOTIFY_ALERT_CLICKED = "gmanager-alert-notify-clicked";
this.NOTIFY_ALERT_FINISHED = "gmanager-alert-notify-finished";
this.FINAL_HEIGHT = 100;
this.SLIDE_INCREMENT = 1;
this.SLIDE_TIME = 10;
this.SWITCH_TIME = 2000;
this.OPEN_TIME = 2000;
this.load = function()
{
// Unwrap the window arguments
if ("arguments" in window && window.arguments.length >= 1)
{
// window.arguments[0] : mail account
// window.arguments[1] : callback listener
this._account = window.arguments[0];
this._callback = window.arguments[1];
}
// Check if the account is specified
if (this._account == undefined)
{
// Close the window
window.close();
}
// Set the account icon
var accountImage = document.getElementById("gmanager-alert-account-image");
accountImage.setAttribute("icontype", this._account.type);
accountImage.setAttribute("status", gmanager_Utils.toStyleStatus(this._account.status));
// Set the account alias
var accountLabel = document.getElementById("gmanager-alert-account-label");
accountLabel.setAttribute("value", this._account.alias);
accountLabel.setAttribute("tooltiptext", this._account.alias);
// Check if the account is logged in
if (this._account.loggedIn)
{
// Get the account snippets
this._snippets = this._account.getSnippets({});
if (this._snippets === null || this._snippets.length === 0)
{
// Close the window
window.close();
}
// Populate the first snippet
this.firstSnippet();
}
else
{
document.getElementById("gmanager-alert-navigation-hbox").collapsed = true;
document.getElementById("gmanager-alert-details-grid").collapsed = true;
document.getElementById("gmanager-alert-description").setAttribute("clickable", false);
document.getElementById("gmanager-alert-description").firstChild.nodeValue = this.getString("login");
}
try {
var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
if (prefService !== null)
{
var branch = prefService.getBranch("alerts.");
this.SLIDE_INCREMENT = branch.getIntPref("slideIncrement");
this.SLIDE_TIME = branch.getIntPref("slideIncrementTime");
this.OPEN_TIME = branch.getIntPref("totalOpenTime");
}
} catch(e) {
/* Preference branch error */
}
sizeToContent();
this.FINAL_HEIGHT = window.outerHeight;
window.outerHeight = 1;
window.moveTo((screen.availLeft + screen.availWidth - window.outerWidth) - 10, screen.availHeight - window.outerHeight);
setTimeout(gmanager_Alert._animateOpen, gmanager_Alert.SLIDE_TIME);
}
this._populateSnippet = function(aIndex)
{
var snippet = this._snippets[aIndex];
document.getElementById("gmanager-alert-count-label").value = this.getFString("count", [this._snippetIndex + 1, this._snippets.length]);
document.getElementById("gmanager-alert-from-label").value = gmanager_Utils.toUnicode(snippet.from);
document.getElementById("gmanager-alert-date-label").value = gmanager_Utils.toUnicode(snippet.date);
document.getElementById("gmanager-alert-subject-label").value = gmanager_Utils.toUnicode(snippet.subject);
document.getElementById("gmanager-alert-description").firstChild.nodeValue = gmanager_Utils.toUnicode(snippet.msg);
}
this.nextSnippet = function()
{
if (this._isNext())
this._populateSnippet(++this._snippetIndex);
}
this.previousSnippet = function()
{
if (this._isPrevious())
this._populateSnippet(--this._snippetIndex);
}
this.firstSnippet = function()
{
this._snippetIndex = 0;
this._populateSnippet(this._snippetIndex);
}
this.lastSnippet = function()
{
this._snippetIndex = this._snippets.length - 1;
this._populateSnippet(this._snippetIndex);
}
this._isNext = function()
{
return (this._snippetIndex < this._snippets.length - 1);
}
this._isPrevious = function()
{
return (this._snippetIndex > 0);
}
this._animateOpen = function()
{
if (window.outerHeight < gmanager_Alert.FINAL_HEIGHT)
{
window.screenY -= gmanager_Alert.SLIDE_INCREMENT;
window.outerHeight += gmanager_Alert.SLIDE_INCREMENT;
setTimeout(gmanager_Alert._animateOpen, gmanager_Alert.SLIDE_TIME);
}
else
setTimeout(gmanager_Alert._slideshow, gmanager_Alert.SWITCH_TIME);
}
this._animateClose = function()
{
if (window.outerHeight > 1)
{
window.screenY += gmanager_Alert.SLIDE_INCREMENT;
window.outerHeight -= gmanager_Alert.SLIDE_INCREMENT;
setTimeout(gmanager_Alert._animateClose, gmanager_Alert.SLIDE_TIME);
}
else
{
// Close the alert
gmanager_Alert.close();
}
}
this._slideshow = function()
{
if (gmanager_Alert._isNext())
{
gmanager_Alert.nextSnippet();
setTimeout(gmanager_Alert._slideshow, gmanager_Alert.SWITCH_TIME);
}
else
setTimeout(gmanager_Alert._animateClose, gmanager_Alert.OPEN_TIME);
}
this.click = function()
{
// Check if the callback listener is specified
if (this._callback != undefined && typeof this._callback.observe == "function")
{
// Notify the observer that the alert was clicked
this._callback.observe(null, gmanager_Alert.NOTIFY_ALERT_CLICKED, this._account.email);
}
// Close the alert
gmanager_Alert.close();
}
this.close = function()
{
// Close the window
window.close();
// Check if the callback listener is specified
if (this._callback != undefined && typeof this._callback.observe == "function")
{
// Notify the observer that the alert has finished
this._callback.observe(null, gmanager_Alert.NOTIFY_ALERT_FINISHED, this._account.email);
}
}
}